<!doctype html>
<html>

<head>
    <meta charset="UTF-8">
    <meta name="viewport"
          content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0"/>
    <meta name="format-detection" content="telephone=no,email=no,date=no,address=no">
    <title>账号与安全</title>
    <link rel="stylesheet" type="text/css" href="../../css/api.css"/>
    <link rel="stylesheet" type="text/css" href="../../css/style.css"/>
    <link rel="stylesheet" type="text/css" href="../../css/common.css"/>
    <link rel="stylesheet" type="text/css" href="../../css/member.css"/>
    <script type="text/javascript" src="../../script/jquery-1.9.1.min.js"></script>
    <script type="text/javascript" src="../../script/mobile.js"></script>
    <script type="text/javascript">
        window['adaptive'].desinWidth = 750;
        window['adaptive'].baseFont = 28;
        window['adaptive'].maxWidth = 750;
        window['adaptive'].init();
    </script>
</head>

<body>
<div id="header" style="height: 0.9rem; background: #fff; position: fixed; top: 0;left: 0; width: 100%; z-index: 99">
    <header class="header header-shadow">
        <div class="header-left">
            <div tapmode onclick="comeBack();" class="nav-left"><img class="icon-back" src="../../icon/icon-back.png"/>
            </div>
        </div>
        <h2>账号与安全</h2>
    </header>
</div>
<div class="header-h"></div>
<div class="mescroll" id="mescroll" style="padding-top: 1.5rem;">

    <section class="html_section bg-f5 pb20">
        <div class="bg-fff pl30 pr30">
            <div class="account_box">
                <div class="line_center">
                    <div class="account_img"><img src="../../icon/icon-phone.png" style="width: 0.23rem;"/></div>
                    <span class="mr35">手机号</span>
                    <span class="f26 c-666">已绑定 <em id="phone"></em></span>
                </div>
                <div tapmode onclick="commonUrl('../login/change_tel')" class="btn btn5">修改</div>
            </div>
        </div>
        <div class="bg-fff mt20 pl30">
            <div class="pr30 between pt30 pb30"><span class="b">第三方帐号绑定</span><span class="c-666 f26">绑定账号均可登录</span></div>
            <div class="account_box three_bang pr30 bb" id="wx">
                <div class="line_center">
                    <div class="account_img">
                        <img class="on" src="../../icon/three-wx.png" style="width: 0.35rem;"/>
                        <img class="off" src="../../icon/three-wx-off.png" style="width: 0.35rem;"/>
                    </div>
                    <span class="mr35 bang-name">微信</span>
                    <span class="f26 c-666" id="wxId">未绑定</span>
                </div>
                <div class="btn btn4" onclick="wxBang(1);">绑定</div>
                <div class="btn btn5" onclick="wxBang(2);">修改</div>
            </div>
            <div class="account_box three_bang pr30 bb" id="qq">
                <div class="line_center">
                    <div class="account_img">
                        <img class="on" src="../../icon/three-qq.png" style="width: 0.35rem;"/>
                        <img class="off" src="../../icon/three-qq-off.png" style="width: 0.35rem;"/>
                    </div>
                    <span class="mr35 bang-name">QQ</span>
                    <span class="f26 c-666" id="qqId">未绑定</span>
                </div>
                <div class="btn btn4" onclick="QQBang(1)">绑定</div>
                <div class="btn btn5" onclick="QQBang(2)">修改</div>
            </div>
            <div class="account_box three_bang pr30" id="wb">
                <div class="line_center">
                    <div class="account_img">
                        <img class="on" src="../../icon/three-wb.png" style="width: 0.35rem;"/>
                        <img class="off" src="../../icon/three-wb-off.png" style="width: 0.35rem;"/>
                    </div>
                    <span class="mr35 bang-name">微博</span>
                    <span class="f26 c-666" id="wbId">未绑定</span>
                </div>
                <div class="btn btn4" onclick="wbBang(1)">绑定</div>
                <div class="btn btn5" onclick="wbBang(2)">修改</div>
            </div>
        </div>
        <div class="bg-fff mt20 pl30 pr30">
            <div class="account_box" tapmode onclick="commonUrl('../login/change_pwd')">
                <div class="line_center">
                    <div class="account_img"><img src="../../icon/icon-password.png" style="width: 0.23rem;"/></div>
                    <span class="mr35" id="pwdStatus">设置密码</span>
                </div>
                <img class="arr_move" src='../../icon/move.png'/>
            </div>
        </div>
        <div class="common-fixed-bottom" style="display: none;">
            <a href="javascript:void (0);" class="fixed-bottom" tapmode onclick="openApp()">注销账号</a>
        </div>
    </section>
</div>

<section class="mask_pop">
    <div class="mask"></div>
    <div class="msg_pop2 pop pb20" style="display: none;">
        <div class="msg_pop_title">通知</div>
        <div class="msg_pop_content" style="text-align: center;">您确定要注销该账号吗？ <br>注销后无法再次登录</div>
        <div class="flex_center pb20">
            <div class="btn7 mr30" onclick="cancelUserName();">确定注销</div>
            <div class="btn6" onclick="popClose();">取消</div>
        </div>
    </div>
</section>


</body>

</html>
<script type="text/javascript" src="../../script/api.js"></script>
<script type="text/javascript" src="../../script/common.js"></script>
<link rel="stylesheet" type="text/css" href="../../css/mescroll.min.css"/>
<script type="text/javascript" src="../../script/mescroll.min.js"></script>
<script type="text/javascript">
    apiready = function () {
        setFixStatusBar(); //
        //监听绑定手机号修改过后修改当前页面绑定手机号
        api.addEventListener({
            name: 'account'
        }, function (ret, err) {
            getMemberInfo()
        });
        //检测是否绑定第三方
        checkBang();
        keybackListener()
        var system = api.systemType
        if(system == 'ios'){
            $(".common-fixed-bottom").hide()
        }else {

            switchController2(function(res){
              if(res.data == 1){
                $(".common-fixed-bottom").show()
              }else {
                $(".common-fixed-bottom").hide()
              }
            })
            
        }
    }

    function openApp() {
        $(".mask").show();
        $(".mask_pop").addClass("on");
        $(".msg_pop2").show();
    }

    function popClose() {
        $(".mask").hide();
        $(".mask_pop").removeClass("on");
    }

    //注销账号
    function cancelUserName() {

        var param = {
            token: $api.getStorage('token')
        }
        pop.loading();
        getAjax(Interface.member_del, param, function (res) {

            $api.setStorage('token', null);
            $api.setStorage('userInfo', null);
            $api.setStorage('schoolPath', null);

            api.closeWin({
                name: 'member',
            })
            individualUrl('../login/login_pwd');

            pop.close();
        }, function (error) {
            pop.close();
        })

    }


    //创建MeScroll对象
    var mescroll = new MeScroll("mescroll", {
        down: {
            auto: false, //是否在初始化完毕之后自动执行下拉回调callback; 默认true
            callback: downCallback //下拉刷新的回调
        }
    });
    /*下拉刷新的回调 */
    function downCallback() {
        getMemberInfo()

        //mescroll.endErr();
    }



    //检测是否绑定第三方 and 是否设置密码
    function checkBang() {
        var userInfo = $api.getStorage('userInfo');
        //隐藏手机号
        $("#phone").html(hideTel(userInfo.tel));
        if (userInfo.qq_id != 0) {
            $("#qq").addClass('active');
            $("#qqId").html('已绑定');
        }
        if (userInfo.wx_id != 0) {
            $("#wx").addClass('active');
            $("#wxId").html('已绑定');
        }
        if (userInfo.wb_id != 0) {
            $("#wb").addClass('active');
            $("#wbId").html('已绑定');
        }
        if (userInfo.password != 0) {
            $("#pwdStatus").html('修改密码');
        }
    }

    //获取用户信息
    function getMemberInfo() {
        var param = {
            token: $api.getStorage('token')
        }
        pop.loading();
        getAjax(Interface.memberIndex, param, function (res) {
            $api.setStorage('userInfo', res.data);
            checkBang();
            pop.close();
            mescroll.endErr()
        }, function (error) {
            pop.notice('读取数据失败');
            mescroll.endErr()
        })
    }

    //绑定微信
    function wxBang(stype) {
        wxLogin(function (ret) {
            var p = {token: $api.getStorage('token'), outher_id: ret.unionid, type: 1, stype: stype,}
            threeLogin(p);
        })
    }


    function QQBang(stype) {
        QQLogin(function (ret) {
            var p = {token: $api.getStorage('token'), outher_id: ret.openId, type: 2, stype: stype,}
            threeLogin(p);
        });
    }
    function wbBang(stype) {
        WeiBoLogin(function (ret) {

            var p = {token: $api.getStorage('token'), outher_id: ret.userId, type: 3, stype: stype,}
            console.log(jsonChange(p));
            threeLogin(p);
        });
    }

    function threeLogin(p) {
        getAjax(Interface.bind_auth, p, function (res) {
            console.log('bangding');
            pop.close();
            getMemberInfo();
        }, function (res, err) {
            console.log('shibai');
        })
    }
</script>
